package cn.reflection;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @auth wzy
 * @date 2023/9/26 16:16
 */
public class Test3 {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException, NoSuchFieldException {
//        new Person();

        Class pc = Person.class;

        Object o = pc.newInstance();

        Field field = pc.getField("message");
        field.set(o,"国庆放假咯");

        System.out.println("field.get(o) = " + field.get(o));

        Field nameField = pc.getDeclaredField("name");
        nameField.setAccessible(true);
        nameField.set(o,"中秋节");
        System.out.println("nameField.get(o) = " + nameField.get(o));


        Method silentMethod = pc.getDeclaredMethod("silentMethod");
        silentMethod.setAccessible(true);
        silentMethod.invoke(o,null);
    }
}
